//
//  ZTNoControlDevice.m
//  YSSmartHome
//
//  Created by yanghao on 2016/11/24.
//  Copyright © 2016年 yahaong. All rights reserved.
//

#import "ZTNoControlDevice.h"
#import "DataManager.h"
#import "MQTTSessionManager.h"


@interface ZTNoControlDevice ()
@property (nullable, nonatomic, strong) MQTTSessionManager* sessionManager;
@property (nullable, nonatomic, strong) DataManager* dataManager;
@end
@implementation ZTNoControlDevice


- (void)reciveStatus:(uint32_t)gatewayApsn
          deviceLuid:(uint64_t )deviceLuid
         triggerApsn:( uint32_t)triggerApsn
         triggerLuid:(uint64_t)triggerLuid
           timestamp:(uint32_t)timestamp
            statusID:(uint8_t)statusID
                data:(XAITLV*__nonnull)data
           isHistory:(BOOL)isHistory
{
    if (!data) {
        NSLog(@"reciveStatus收到data为空");
        return;
    }
    [super reciveStatus:gatewayApsn deviceLuid:deviceLuid triggerApsn:triggerApsn triggerLuid:triggerLuid timestamp:timestamp statusID:statusID data:data isHistory:isHistory];
    switch (statusID)
    {
        case 0x01:
        {
            uint8_t status = 0;
            memcpy(&status, [data getPayloadbyte], sizeof(uint8_t));
            if (isHistory) {
                NSString *str = nil;
                switch (self.devType)
                {
                    
                    case ZTDeviceTypeZTDoorsensor:
                    {
                        if (status == ZTDeviceChannelStatusOn)
                        {
                            str = [NSString stringWithFormat:@"%@触发",[self getDeviceName]];
                        }
                        else
                        {
                            str = [NSString stringWithFormat:@"%@关闭",[self getDeviceName]];
                        }
                    }
                        break;
                    case ZTDeviceTypeAlarmkey:
                    case ZTDeviceTypeInfraredDetector:
                    {
                        if (status == ZTDeviceChannelStatusOn)
                        {
                            str = [NSString stringWithFormat:@"%@触发",[self getDeviceName]];
                        }
                    }
                        break;
                    default:
                        break;
                }
                [super updateOperationWithGatewayApsn:gatewayApsn deviceLuid:deviceLuid triggerApsn:triggerApsn triggerLuid:triggerLuid timestamp:timestamp operation:str];
            }
            else
            {
                self.status = status;
                [kDataManager deviceRefreshCallBackWithType:DeviceCallbackTypeStatus];
            }
        }
            break;
        default:
            break;
    }
}
@end
